package com.sense.cloud.send.app;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.jboss.resteasy.core.ResourceMethodInvoker;
import org.jboss.resteasy.core.interception.PostMatchContainerRequestContext;
import org.jboss.resteasy.spi.HttpRequest;

public class BodyPostMatchContainerRequestContext extends PostMatchContainerRequestContext {
	private final byte[] body;

	public byte[] getBody() {
		return body;
	}

	public BodyPostMatchContainerRequestContext(HttpRequest request, ResourceMethodInvoker resourceMethod)
			throws IOException {
		super(request, resourceMethod);
		InputStream ins = request.getInputStream();
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		byte[] bs = new byte[1024];
		int i = 0;
		while ((i = ins.read(bs)) > -1) {
			bos.write(bs, 0, i);
		}
		body = bos.toByteArray();
		bos.flush();
		bos.close();
	}

}
